package cn.edu.zafu.bigdata.sxa;

public class StaticDemo {
    private static int count=0;
    private int id;

    static {
        System.out.println("Static block executed");
        count = 0; // 初始化静态变量 count
    }

    {
        System.out.println("Instance block executed");
        id = count;
        count++;
    }

    public StaticDemo() {
        System.out.println("Constructor executed for ID: " + id);
    }

    public static void displayCount(){
        System.out.println("当前已创造"+(count+1)+"个实例");
    }


    public static void main(String[] args) {
        StaticDemo demo1 = new StaticDemo();
        StaticDemo demo2 = new StaticDemo();
        StaticDemo demo3 = new StaticDemo();

        StaticDemo.displayCount();
    }
}


